package com.gcc.crudmysqldemo.service;

import com.gcc.crudmysqldemo.model.Animal;
import com.gcc.crudmysqldemo.repository.AnimalRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;

@Service
public class AnimalService {
    @Autowired
    private AnimalRepository animalRepository;
    public Animal save(Animal animal) {
        return animalRepository.save(animal);
    }
    public List<Animal> findAll(){
        return animalRepository.findAll();
    }
    public Optional<Animal> findById(Long id) {
        return animalRepository.findById(id);
    }

    public boolean deleteById(Long id) {
        if(animalRepository.existsById(id)){
            animalRepository.deleteById(id);
            return true;
        }
        return false;
    }
}
